A c++ compile time error.

C++ compile time error: expected identifier before numeric constant

source: https://stackoverflow.com/questions/11490988/c-compile-time-error-expected-identifier-before-numeric-constant

You cannot do this:

1
2
vector<string> name(5); //error in these 2 lines
vector<int> val(5,0);

in a class outside of a method.

You can initialize the data members at the point of declaration, but not with () brackets:

1
2
3
4
class Foo {
vector<string> name = vector<string>(5);
vector<int> val{vector<int>(5,0)};
};

Before C++11, you need to declare them first, then initialize them e.g in a contructor

1
2
3
4
5
6
class Foo {
vector<string> name;
vector<int> val;
public:
Foo() : name(5), val(5,0) {}
};